<template>
    <div class="body">
        <div class="login-content">
            <div class="input-content">
                <input type="text" autofocus v-model="code" placeholder="请扫描箱子二维码" @keyup.enter="getCode">
                <!-- <button @click="getCode">提交</button> -->
            </div>
        </div>
        <mt-button size="large" plain type="danger" @click.native="loginOut">退出登录</mt-button>
    </div>
</template>
<script>
import {boxUse} from '../api'
import {Toast} from 'mint-ui'
import cookie from '../cookie'
export default {
    data() {
        return {
            code:'',
            // roleinfo:{},
        }
    },
    created(){
        // this.roleinfo = JSON.parse(cookie.get('data','roleinfo'));
    },
    methods:{
        getCode(){
            const {code} = this;
            if(code.length!==20){
                Toast("请扫描正确的二维码");
                return;
            }
            const data = {
                 type:2,
                 code,
                 token:cookie.get('data','token')
            }
            boxUse(data).then(res=>{
                // console.log(res);
                if(res.code == 200){
                    Toast('箱子状态修改成功，正在配送中，请尽快送达');
                }else{
                    Toast('修改失败，请重新再试');
                }
                this.code = '';
            })
        },
        loginOut(){
            cookie.unsetAll('data');
            this.$router.push('/');
        }
    }
}
</script>
<style scoped>
    .body{
        height: 100vh;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
    }
</style>